namespace Stee.CAP8.Communication.ClientSample
{
    using System;
    using Microsoft.Extensions.DependencyInjection;
    using Stee.CAP8.Communication.GrpcInterface;
    using Stee.CAP8.Communication.ServiceSample;
    using Stee.CAP8.Service.Shared.Converters;

    public class Program
    {
        public static async System.Threading.Tasks.Task Main()
        {
            var service = new ServiceCollection();

            var optionBuilder = new GrpcClientOptionBuilder(null);
            optionBuilder.SetServerAddress("https://localhost:5001").AddGrpcClientConfig(new GrpcClientInfo() { GrpcClientTypeName = "GreeterClient" });

            service.AddGrpcGroupClient(optionBuilder.CurrentOption);

            

            var provider = service.BuildServiceProvider(validateScopes: true);
            var client = provider.GetClient<Greeter.GreeterClient>();

            var myRequest = new MyReqObject() { ID = 1, Name = "developer" };
            var protobufRequest = ProtobufConvertor.ToProtobufMesssage<MyReqObject, HelloRequest>(myRequest);

            var protobufResponse = await client.SayHelloAsync(protobufRequest);
            var myResponse = ProtobufConvertor.ToObject<MyRespObject>(protobufResponse);
            Console.WriteLine($"ID: {myResponse.ID}, Message :{myResponse.Message}");
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
    }

    public class MyReqObject
    {
        public int ID
        {
            get; set;
        }

        public string Name
        {
            get; set;
        }
    }

    public class MyRespObject
    {
        public int ID
        {
            get; set;
        }

        public string Message
        {
            get; set;
        }
    }
}
